package com.teacher.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teacher.common.CommonResult;
import com.teacher.pojo.dto.PageDto;
import com.teacher.pojo.entity.School;
import com.teacher.mapper.SchoolMapper;
import com.teacher.service.ISchoolService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jiangzhuohang
 * @since 2024-03-14
 */
@Service
public class SchoolServiceImpl extends ServiceImpl<SchoolMapper, School> implements ISchoolService {

    @Autowired
    private SchoolMapper schoolMapper;

    @Override
    public CommonResult getSchoolByName(String name) {
        List<School> schools = schoolMapper.selectList(new QueryWrapper<School>().lambda().like(School::getSchoolName, name));
        return CommonResult.success(schools);
    }

    @Override
    public CommonResult getSchoolListPage(PageDto pageDto) {
        Page<School> schoolPage = new Page<School>(pageDto.getCurrentPage(),pageDto.getPageSize(),true);
        IPage<School> schoolIPage = schoolMapper.selectPage(schoolPage, new QueryWrapper<School>());
        return CommonResult.success(schoolIPage);
    }
}
